<template>
 <div class="">
    <div class="userinfo" >
        <div class="uinfo">
        <div class="uinfo1" >
          <open-data type="userAvatarUrl"></open-data>
        </div>
        <div class="uinfo2">          
          <open-data class="uname" type="userNickName" lang="zh_CN"></open-data>
          <img class="imgcls1" src="/static/images/mon.png"  @click="gopage('/pages/revenue/main')"/>
          <img class="imgcls1" src="/static/images/xjjj.png"  @click="gopage('/pages/disp/main')"/>
        </div>
      </div>
    </div>

    <div class="cad">
      <div class="cad1">
        <div class="cadimg" @click="gopage('/pages/addr/main')">
          <img class="imgcls" src="/static/images/rl6.png"/>
        </div>
        <div class="cadinfo" @click="gopage('/pages/addr/main')">{{lm1}}</div>
        <div class="cadbut"  @click="gopage('/pages/addr/main')">
          <img class="imgcls" src="/static/images/in.png"/>
        </div>
        
      </div>
      <div class="cad1">
        <div class="cadimg"  @click="copyCode()">
          <img class="imgcls" src="/static/images/iqg.png"/>
        </div>
        <div class="cadinfo3"  @click="copyCode()">授权码</div>
        <div class="cadbut2">
          <img class="imgcls mmg" src="/static/images/copy.png"  @click="copyCode()"/>
          <img class="imgcls mmg" src="/static/images/update.png"  @click="updateCode()"/>
        </div>
      </div>

      <div class="cad1">
        <div class="cadimg"  @click="getQrCode()">
          <img class="imgcls"  src="/static/images/qrcode.png"/>
        </div>
        <div class="cadinfo"  @click="getQrCode()">我的二维码</div>
        <div class="cadbut"  @click="getQrCode()">
          <img class="imgcls" src="/static/images/in.png"/>
        </div>
      </div>

      <div class="cad1">
        <div class="cadimg" @click="gopage('/pages/about/main')">
          <img class="imgcls"  src="/static/images/sys1.png"/>
        </div>
        <div class="cadinfo" @click="gopage('/pages/about/main')">关于系统</div>
        <div class="cadbut" @click="gopage('/pages/about/main')">
          <img class="imgcls" src="/static/images/in.png"/>
        </div>
      </div>

      <!-- <div class="disss1">平台遵守《用户个人信息保护》和《用户隐私和数据规范》</div> -->
      <!-- <div class="disss" @click="getVisitCode()">我要成为代理</div> -->
    </div>
  </div>
</template>
<script>
import { requestPost } from '@/utils/index'
export default {
  data () {
    return {
      userInfo: {},
      utime: 0,
      ctime: 0,
      lm1: ''
    }
  },
  onLoad () {},
  onShow () {
    if (mpvue.getStorageSync('co')) {
      this.lm1 = '人脸核身'
    } else {
      this.lm1 = '商品信息'
    }
  },
  onUnload () {
    mpvue.removeStorageSync('token')
  },
  methods: {
    getQrCode () {
      var data = {
        'token': mpvue.getStorageSync('token')
      }
      requestPost(mpvue.getStorageSync('requestUrl') + '/miniprogram/getQrCode', data, 'POST').then(function (value) {
        if (value.code === 0) {
          wx.previewImage({
            current: value.data, // 当前显示图片的http链接
            urls: [value.data] // 需要预览的图片http链接列表
          })
        }
      })
    },
    getVisitCode () {
      if (!mpvue.getStorageSync('co')) {
        wx.showToast({
          title: '恭喜您已成为代理',
          icon: 'none',
          duration: 3000,
          mask: false
        })
        return
      }
      var data = {
        'userId': mpvue.getStorageSync('userId'),
        'token': mpvue.getStorageSync('token')
      }
      var url = mpvue.getStorageSync('requestUrl') + '/miniprogram/visitCode'
      requestPost(url, data, 'POST').then(function (value) {
        if (value.code === 0) {
          wx.showModal({
            title: '是否成为代理商',
            content: '代理商佣金高达90%',
            success (res) {
              if (res.confirm) {
                console.log('用户点击确定')
                var data = {
                  'type': '3',
                  'userId': mpvue.getStorageSync('userId'),
                  'token': mpvue.getStorageSync('token')
                }
                requestPost(mpvue.getStorageSync('requestUrl') + '/wxPay/unifiedOrder', data, 'POST').then(function (value) {
                  if (value.code === 0) {
                    wx.requestPayment({
                      timeStamp: value.data.timeStamp,
                      nonceStr: value.data.nonceStr,
                      package: value.data.package,
                      signType: value.data.signType,
                      paySign: value.data.paySign,
                      success (res) {
                        wx.showToast({
                          title: '支付成功',
                          icon: 'none',
                          duration: 2000,
                          mask: false
                        })
                      },
                      fail (res) {
                        console.log('支付失败')
                      }
                    })
                  }
                })
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
        } else if (value.code === 200041) {
          wx.showToast({
            title: '您已是代理商',
            icon: 'none',
            duration: 2000,
            mask: false
          })
        } else if (value.code === 200032) {
          wx.showToast({
            title: '您还未人脸核身',
            icon: 'none',
            duration: 2000,
            mask: false
          })
        } else {
          wx.showToast({
            title: value.message,
            icon: 'none',
            duration: 2000,
            mask: false
          })
        }
      }, function (value) {
        console.log(value.message)
      })
    },
    copyCode () {
      if (!mpvue.getStorageSync('co')) {
        wx.showToast({
          title: '联系客服获取',
          icon: 'none',
          duration: 3000,
          mask: false
        })
        return
      }
      var data = {
        'userId': mpvue.getStorageSync('userId'),
        'token': mpvue.getStorageSync('token')
      }
      var that = this
      var url = mpvue.getStorageSync('requestUrl') + '/miniprogram/getCode'
      requestPost(url, data, 'POST').then(function (value) {
        if (value.code === 200032) {
          wx.showToast({
            title: '您还未进行“人脸核身”',
            icon: 'none',
            duration: 3000,
            mask: false
          })
          that.gopage('/pages/addr/main')
          return
        }
        if (value.code === 0) {
          wx.setClipboardData({
            data: value.data,
            success (res) {
              wx.getClipboardData({
                success (res) {
                  // console.log(res.data) // data
                }
              })
            }
          })
        } else {
          wx.showToast({
            title: value.message,
            icon: 'none',
            duration: 2000,
            mask: false
          })
        }
      }, function (value) {
        console.log('复制失败')
      })
    },
    updateCode () {
      if (!mpvue.getStorageSync('co')) {
        wx.showToast({
          title: '联系客服更新',
          icon: 'none',
          duration: 3000,
          mask: false
        })
        return
      }
      wx.showModal({
        title: '是否更新授权码',
        content: '原授权码将失效',
        success (res) {
          if (res.confirm) {
            console.log('用户点击确定')
            var data = {
              'userId': mpvue.getStorageSync('userId'),
              'token': mpvue.getStorageSync('token')
            }
            var url = mpvue.getStorageSync('requestUrl') + '/miniprogram/updateCode'
            requestPost(url, data, 'POST').then(function (value) {
              if (value.code === 200032) {
                wx.showToast({
                  title: '您还未进行“人脸核身”',
                  icon: 'none',
                  duration: 3000,
                  mask: false
                })
                return
              }
              if (value.code === 0) {
                wx.showToast({
                  title: '授权码更新成功',
                  icon: 'success',
                  duration: 2000,
                  mask: false
                })
              } else {
                wx.showToast({
                  title: value.message,
                  icon: 'none',
                  duration: 2000,
                  mask: false
                })
              }
            }, function (value) {
              console.log('更新失败')
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    },
    gopage (pathstr) {
      wx.navigateTo({
        url: pathstr
      })
    }
  }
}
</script>
<style>
.mmg{
  margin-right: 20px;
}
.cadbut{
  width: 30%;
  height: 50px;
  text-align: right;
  float: right;
}
.cadbut2{
  width: 40%;
  height: 50px;
  text-align: right;
  float: right;
}
.cadinfo{
  width:55%;
  height: 50px;
  float: left;
}
.cadinfo1{
  width:55%;
  height: 50px;
  float: left;
}
.cadinfo3{
  width:30%;
  height: 50px;
  float: left;
}
.cadimg{
  width: 15%;
  height: 50px;
  float: left;
}
.imgcls{
  width:30px;
  height: 30px;
  margin-top:10px;
  margin-left: 10px;
}
.imgcls1{
  margin-left: 10px;
  width:40px;
  height: 40px;
  float: left;
  /* padding-left: 10px; */
}
.uname{
  width: 40%;
  height: 40px;
  line-height: 40px;
  font-size: 17px;
  overflow: hidden;
  font-weight: bold;
  /* border: 1px solid rgb(37, 34, 235); */
  text-align: right;
  float: left;
}
.uinfo{
  width: 200px;
  height: 200px;
  margin: 0px auto;
}
.uinfo1{
  width: 100%;
  /* border: 0px rgb(224, 224, 224) solid; */
  border-radius: 50%;
  overflow: hidden;

}
.uinfo2{
  width: 100%;
  /* border: 2px rgb(224, 224, 224) solid; */
  /* border-radius: 50%; */
/* overflow: hidden; */

}
.butt1{
  height: 100px;
  /* margin-top:20px; */
}
.loginBut{
  width: 50%;
  /* margin-top:30px; */
  background-color: rgba(218, 218, 218, 0);
}
.ubut{
  width:35%;
  height: 100px;
  line-height: 100px;
  margin-top: 25px;
  font-size: 20px;
  float: right;
}
.userinfo {
  width: 100%;
  height: 250px;
  background-color: #FEF55A;
}
.cad{
  width: 100%;
  float: left;
}
.disp{
  width: 100%;
  float: left;
  margin-top: 5px;
  margin-bottom: 5px;
}
/* .userinfo-avatar {
  width: 200px;
  height: 200px;
  border-radius: 50%;
} */

.cad1{
  width: 100%;
  height: 50px;
  line-height: 50px;
  font-size: 20px;
  margin-bottom: 1px;
  margin-top:5px;
  background-color: rgba(255, 255, 255, 0.692);
  border-bottom: 1px solid rgb(218, 218, 218);
}
.cpcode{
  width: 45%;
  height: 60px;
  /* border: 1px solid red; */
  border-radius: 10px 10px 10px 10px;
  background-color: #FEF55A;
  margin-left: 15px;
  float: left;
  text-align: center;
  font-size: 20px;
  color:red;
  font-weight: bold;
  line-height: 60px;
}
.lookmoney{
  width: 45%;
  height: 60px;
  /* border: 1px solid red; */
  border-radius: 10px 10px 10px 10px;
  background-color: #FEF55A;
  margin-right: 15px;
  float: right;
  text-align: center;
  line-height: 60px;
}
.monpng{
  /* border:1px solid red; */
  width: 40%;
  height: 60px;
  float: left;
  display: flex; 
  align-items: center;
  /* display: table-cell; */
	/* vertical-align: middle; */
	text-align: center; 
}
.lsy{
  /* border:0px solid red; */
  width: 55%;
  float: left;
  text-align: left;
  font-size: 20px;
  color:red;
  font-weight: bold;
}

.imgcls90{
  width:40px;
  height: 40px;
  margin: 0 auto;
  /* margin-top:10px;
  margin-left: 10px; */
}
.disss{
  width: 95%;
  height: 30px;
  font-size: 15px;
  line-height: 30px;
  color: rgb(101, 136, 250);
  text-align: right;
  float: left;
  margin-top: 20px;
  text-decoration: underline;
  font-style: italic;
  
}
.disss1{
  width: 95%;
  height: 30px;
  font-size: 14px;
  line-height: 30px;
  color: rgb(199, 199, 199);
  text-align: center;
  float: left;
  margin-top: 20px;
  
}
</style>
